<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::prefix('v1')->name('api.v1.')->group(function () {

    Route::namespace('User')->group(function () {
        Route::get('wx_pay_notify', 'PayController@wxPayNotify')->name('pau.wxPayNotify');
        Route::post('wx_pay_notify', 'PayController@wxPayNotify')->name('pau.wxPayNotify');
    });

    Route::prefix('auth')->group(function () {
        Route::post('wx', 'AuthController@wxLogin')->name('auth.wxLogin');
    });

    Route::middleware('auth:sanctum')->group(function () {
        Route::post('upload', 'IndexController@upload')->name('index.upload');
        Route::get('stat', 'IndexController@stat')->name('index.stat');
    });

    Route::middleware('auth:sanctum')->group(function () {
        Route::post('advance', 'OrderController@advance')->name('order.advance');
        Route::post('pay/{order_id}', 'OrderController@pay')->name('order.pay');
        Route::get('order', 'OrderController@index')->name('order.index');
        Route::get('order/{id}', 'OrderController@view')->name('order.view');
        Route::post('order', 'OrderController@store')->name('order.store');
        Route::post('order/{id}', 'OrderController@update')->name('order.update');
        Route::post('cancel/{id}', 'OrderController@cancel')->name('order.cancel');
        Route::delete('order/{id}', 'OrderController@destroy')->name('order.destroy');
    });

    Route::get('goods', 'GoodsController@index')->name('goods.index');
    Route::get('goods/{id}', 'GoodsController@view')->name('goods.view');
    Route::get('goods_hot', 'GoodsController@hot')->name('goods.hot');
    Route::get('goods_source/{id}', 'GoodsController@source')->name('goods.source');
    Route::middleware('auth:sanctum')->group(function () {
        Route::get('collect', 'GoodsController@collect')->name('goods.collect');
        Route::post('collect', 'GoodsController@storeCollect')->name('goods.storeCollect');
        Route::post('goods', 'GoodsController@store')->name('goods.store');
        Route::post('goods_scan', 'GoodsController@scan')->name('goods.scan');
        Route::post('goods/{id}', 'GoodsController@update')->name('goods.update');
        Route::delete('goods/{id}', 'GoodsController@destroy')->name('goods.destroy');
    });

    Route::get('comment', 'CommentController@index')->name('comment.index');
    Route::get('comment/{id}', 'CommentController@view')->name('comment.view');
    Route::middleware('auth:sanctum')->group(function () {
        Route::get('comment_reply', 'CommentController@reply')->name('comment.reply');
        Route::post('comment', 'CommentController@store')->name('comment.store');
        Route::post('comment/{id}', 'CommentController@update')->name('comment.update');
        Route::delete('comment/{id}', 'CommentController@destroy')->name('comment.destroy');
    });

    Route::middleware('auth:sanctum')->group(function () {
        Route::get('goods_like', 'GoodsLikeController@index')->name('goods_like.index');
        Route::post('goods_like', 'GoodsLikeController@store')->name('goods_like.store');
        Route::post('goods_like_read', 'GoodsLikeController@read')->name('goods_like.read');
    });

    Route::get('category', 'CategoryController@index')->name('category.index');

    Route::middleware('auth:sanctum')->group(function () {
        Route::get('config', 'ConfigController@index')->name('config.index');
        Route::post('config', 'ConfigController@store')->name('config.store');

        Route::get('address', 'AddressController@index')->name('address.index');
        Route::get('address/{id}', 'AddressController@view')->name('address.view');
        Route::post('address', 'AddressController@store')->name('address.store');
        Route::post('address/{id}', 'AddressController@update')->name('address.update');
        Route::delete('address/{id}', 'AddressController@destroy')->name('address.destroy');

        Route::get('coupon_user', 'CouponUserController@index')->name('address.index');
    });

});


Route::namespace('Wx')->prefix("wx")->group(function () {
    Route::get('check', 'IndexController@check')->name('wx.check');
    Route::get('jssdk', 'IndexController@jssdk')->name('wx.jssdk');
    Route::post('pay/notify', 'PayController@notify')->name('wx_pay.notify');
});
